package doctor

import (
	"github.com/bgmp/config"
	"github.com/bgmp/handler"
	"github.com/bgmp/model"
	"github.com/gin-gonic/gin"
)

func (b Base) GetAllPatients(c *gin.Context, req *GetAllPatientsRequest) *GetAllPatientsResponse {
	condition := req.UserSelectConditions
	condition.Role = model.Patient
	users, err := model.GetUsersByCondition(config.DB, &condition)
	if err != nil {
		handler.Errorf(c, err.Error())
		return nil
	}
	var res GetAllPatientsResponse
	for _, user := range users {
		res.Patients = append(res.Patients, user.GetUserVO())
	}
	return &res
}

type GetAllPatientsRequest struct {
	model.UserSelectConditions
}

type GetAllPatientsResponse struct {
	Patients []*model.UserVO `json:"patients"`
}
